package com.weishi.pay.utils;

import java.util.Date;
import java.util.Random;

/**
 * 生成ID工具类
 * 
 * @author tangtao
 *
 */
public class IdUtils {

	public static long genId() {
		String str = String.format("%1$01d%2$05d", new Random().nextInt(9) + 1, new Random().nextInt(99999));
		return Long.parseLong(str);
	}

	private static Date date = new Date();
	private static StringBuilder buf = new StringBuilder();
	private static int seq = 1;
	private static final int ROTATION = 9999;

	public static synchronized String next() {
		if (seq > ROTATION)
			seq = 1;
		buf.delete(0, buf.length());
		date.setTime(System.currentTimeMillis());
		String str = String.format("%1$tY%1$tm%1$td%1$tk%1$tM%1$tS%2$04d%3$03d", date, seq++,
				new Random().nextInt(999));
		return str;
	}


}
